<template>
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="图书名称">
      <el-input v-model="form.title"></el-input>
    </el-form-item>
    <el-form-item label="作者">
      <el-input v-model="form.author"></el-input>
    </el-form-item>
    <el-form-item label="出版社">
      <el-select v-model="form.press" placeholder="请选择出版社">
        <el-option label="北京大学出版社" value="北京大学出版社"></el-option>
        <el-option label="清华大学出版社" value="清华大学出版社"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="出版日期">
      <el-input v-model="form.date" placeholder = "2020-1-1"></el-input>
    </el-form-item>
    <el-form-item label="是否连载">
      <el-switch v-model="form.isLian"></el-switch>
    </el-form-item>
    <el-form-item label="图书种类">
      <el-radio-group v-model="form.type">
        <el-radio label="文学"></el-radio>
        <el-radio label="文化"></el-radio>
        <el-radio label="生活"></el-radio>
        <el-radio label="科技"></el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="图书简介">
      <el-input type="textarea" v-model="form.abs"></el-input>
    </el-form-item>
    <el-form-item label="图书封面">
      <el-input v-model="form.cover" autocomplete="off" placeholder="图片 URL"></el-input>
      <upload ref="upload" @onUpload="uploadImg"></upload>
    </el-form-item>
    <el-form-item label="图书资源">
      <el-input v-model="form.resource" autocomplete="off" placeholder="txt URL"></el-input>
      <upload_txt ref="upload_txt" @onUpload="uploadTxt"></upload_txt>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">立即导入</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import upload from '@/components/common/upload'
import upload_txt from '@/components/common/upload_txt'
export default {
  name: 'import',
  components: {upload, upload_txt},
  props: {
    fileList :[]
  },
  data() {
    return {
      form: {
        title: '',
        press: '',
        date: '',
        author: '',
        isLian: false,
        type: '',
        resource: '',
        abs: '',
        cover: '',
        lian: ''
      }
    }
  },
  methods: {
    onSubmit() {
      console.log('submit!');
      if (this.isLian == true){
        this.lian = 0
      }else {
        this.lian = 1
      }
      console.log(this.lian)
      this.$axios
        .post('/save_book',{
          title: this.form.title,
          press: this.form.press,
          date: this.form.date,
          author: this.form.author,
          islian: this.lian,
          type: this.form.type,
          resource: this.form.resource,
          abs: this.form.abs,
          cover: this.form.cover
        })
        .then(successResponse => {
          alert("导入成功！")
        })
    },
    uploadImg () {
      this.form.cover = this.$refs.upload.url
    },
    uploadTxt () {
      this.form.resource = this.$refs.upload_txt.url
    }
  }
}
</script>

<style scoped>

</style>
